{
int range_length = to - from;
prepare_to_modify_buffer (from, to, &from);
- to = from + range_length;
+ to = min (ZV, from + range_length);
}
from_byte = CHAR_TO_BYTE (from);
if (old_from != from)
from_byte = CHAR_TO_BYTE (from);
- if (old_to == Z - to)
+ if (to > ZV)
+ {
+ to = ZV;
+ to_byte = ZV_BYTE;
+ }
+ else if (old_to == Z - to)
to_byte = CHAR_TO_BYTE (to);
}
if (old_from != from)
from_byte = CHAR_TO_BYTE (from);
- if (old_to == Z - to)
+ if (to > ZV)
+ {
+ to = ZV;
+ to_byte = ZV_BYTE;
+ }
+ else if (old_to == Z - to)
to_byte = CHAR_TO_BYTE (to);
}